﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ZaxLib.Collections;
using ZaxLib.Web.UI.Events;
using ZaxLib.Web.UI.WebControls;

namespace DemoControls
{
	public partial class Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            // Set the date picker to use today's date
            if (!IsPostBack)
            {
                dpDate.Text = DateTime.Now.ToShortDateString();
            }

            // You can combine both ASPX defined items with programmatically added items
			//int id = 0;
			ddColor.AddItem("Red");
			ddColor.AddItem("Green");
			ddColor.AddItem("Blue");
			ddColor.AddItem("Purple");
			ddColor.AddItem("Yellow");
			ddColor.AddItem("Grey");
			ddColor.AddItem("Black");

			lvColor2.AddItem("Red");
			lvColor2.AddItem("Green");
			lvColor2.AddItem("Blue");
			lvColor2.AddItem("Purple");
			lvColor2.AddItem("Yellow");
			lvColor2.AddItem("Grey");
			lvColor2.AddItem("Black");

		}

		protected void SetupGrid()
		{
			CDataGrid data = new CDataGrid();
			for (int y = 0; y < 60; y++)
			{
				Dictionary<String, Object> row = new Dictionary<String, Object>();
				for (int x = 0; x < 5; x++)
				{
					String key = String.Format("X:{0}", x);
					row[key] = String.Format("{0}", (y * 5) + x);
				}
				data.AddRow(row);
			}
			data.Start();
			gvResults.Data = data;
		}

        protected void OnClicked(Object sender, EventArgs e)
        {
			lblCode.Text = String.Format("Color: {0}<br />\n", ddColor.Text);
            lblCode.Visible = true;
        }

        protected void OnChange(Object sender, EventArgs e)
        {
            lblCode.Text = (sender as DatePicker).Text;
            lblCode.Visible = true;
        }

		protected void OnColorChange(Object sender, EventArgs e)
		{
			lblColor2.Text = lvColor2.Text;
			lblColor2.Visible = true;
		}

		protected void OnYesnoChange(Object sender, EventArgs e)
		{
			ZaxLib.Web.UI.WebControls.ListView list = sender as ZaxLib.Web.UI.WebControls.ListView;
			bool IsYes = list.Text.ToUpper() == "YES";
			divLine.Visible = IsYes;
		}

		protected void OnTextChange(Object sender, EventArgs e)
		{
			if (sender is ZaxLib.Web.UI.WebControls.TextBox)
			{
				ZaxLib.Web.UI.WebControls.TextBox control = sender as ZaxLib.Web.UI.WebControls.TextBox;
				lblUser.Text = control.Text;
				lblUser.Visible = true;
			}
		}

		protected void OnLoginChange(Object sender, EventArgs e)
		{
			if(sender is ZaxLib.Web.UI.WebControls.TextBox)
			{
				ZaxLib.Web.UI.WebControls.TextBox control = sender as ZaxLib.Web.UI.WebControls.TextBox;
				lblUser.Text = control.Text;
				lblUser.Visible = true;
			}
		}

		protected void OnDropZone(Object sender, EventArgs e)
		{
			if(e is DropEventArgs)
			{
				lblCode.Text = String.Format("DropZone: {0}", dropZone.Text);
				lblCode.Visible = true;
				DropEventArgs de = e as DropEventArgs;
				dropZone.AddItem(de.what);
			}
		}

		protected void OnClickPanel(Object sender, EventArgs e)
		{
			if(e is ControlEventArgs)
			{
				ControlEventArgs ce = e as ControlEventArgs;
				lblCode.Text = String.Format("Clicked: {0}", ce.EventData);
				lblCode.Visible = true;
			}
		}

		protected void btnOnClick(Object sender, EventArgs e)
		{
			WebControl control = sender as WebControl;
			// Turn off all controls
			dGridView.Visible = false;
			dDatePicker.Visible = false;
			dTextBox.Visible = false;
			dNoteBox.Visible = false;
			dListView.Visible = false;
			dDragItems.Visible = false;
			dDropPanel.Visible = false;

			switch (control.ID)
			{
				case "btnGrid":
					{
						// Create and fill DataGrid
						SetupGrid();
						dGridView.Visible = true;
					}
					break;
				case "btnDate":
					{
						dDatePicker.Visible = true;
					}
					break;
				case "btnText":
					{
						dTextBox.Visible = true;
					}
					break;
				case "btnNote":
					{
						dNoteBox.Visible = true;
					}
					break;
				case "btnList":
					{
						dListView.Visible = true;
					}
					break;
				case "btnDrag":
					{
						dDragItems.Visible = true;
						dDropPanel.Visible = true;
					}
					break;
			}
		}
	}
}